import { injectUrl, Response } from "@/service/request/baseService";
import request from "@/service/request";

export interface User {
  username: string;
  password: string;
  captchaVerification: string;
  socialType?: string;
  socialCode?: string;
  socialState?: string;
}
export type loginParams = Omit<User, "oldPassword" | "newPassword">;
@injectUrl({ url: "/system/user/profile", serviceName: "登录" })
export class LoginService {
  // 登录
  static login(data: loginParams) {
    return request.post<Response>({
      url: "/system/auth/login",
      isNeedToken: false,
      data,
    });
  }
  // 登录
  static getTenantIdByName(name: string) {
    return request.get<Response>({
      url: "/system/tenant/get-id-by-name",
      isNeedToken: false,
      data: { name: name },
    });
  }

  // 退出方法
  static logout() {
    return request.post({
      url: "/system/auth/logout",
    });
  }

  // 获取验证码
  static getCodeImg() {
    return request.get<
      Response | { uuid: string; img: string; captchaOnOff: boolean }
    >({
      url: "/captchaImage",
      isNeedToken: false,
      timeout: 20000,
    });
  }
}
